package com.wz.project.bas.customer.controller;

import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.bas.customer.domain.Customer;
import com.wz.project.bas.customer.service.ICustomerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 基础客户管理（出库） 信息操作处理
 * 
 * @author sys
 * @date 2021-10-28
 */
@Controller
@RequestMapping("/bas/customer")
public class CustomerController extends BaseController
{
    private String prefix = "bas/customer";
	
	@Autowired
	private ICustomerService customerService;
	
	@RequiresPermissions("bas:customer:view")
	@GetMapping()
	public String customer()
	{
	    return prefix + "/customer";
	}
	
	/**
	 * 查询基础客户管理（出库）列表
	 */
//	@RequiresPermissions("module:customer:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Customer customer)
	{
		startPage();
        List<Customer> list = customerService.selectCustomerList(customer);
		return getDataTable(list);
	}
	
	/**
	 * 新增基础客户管理（出库）
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存基础客户管理（出库）
	 */
	@RequiresPermissions("module:customer:add")
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Customer customer)
	{
		String s = String.valueOf(System.currentTimeMillis());
		String substring = s.substring(s.length() - 6);
//        int pejId = Integer.parseInt(substring);
		customer.setId(substring);
		return toAjax(customerService.insertCustomer(customer));
	}

	/**
	 * 修改基础客户管理（出库）
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		Customer customer = customerService.selectCustomerById(id);
		mmap.put("customer", customer);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存基础客户管理（出库）
	 */
	@RequiresPermissions("module:customer:edit")
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Customer customer)
	{		
		return toAjax(customerService.updateCustomer(customer));
	}
	
	/**
	 * 删除基础客户管理（出库）
	 */
	@RequiresPermissions("module:customer:remove")
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(customerService.deleteCustomerByIds(ids));
	}
	
}
